package cn.sdhuijin.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.sdhuijin.service.PDFService;

import com.itextpdf.text.DocumentException;

/**
 * @author houyc
 * @version 创建时间：2015-05-08
 */

@Controller
public class PDFController {

	@Inject
	private PDFService pdfService;

	@ResponseBody
	@RequestMapping(value = { "/expoertstandard" })
	public Map<String, Object> exportStandardPdfByID(
			@RequestParam("standardId") String standardId, HttpSession session)
			throws DocumentException, IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean result = false;
		try {
			Long id = Long.valueOf(standardId);
			result = pdfService.exportStandardPdfByID(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (!result) {
			map.put("success", false);
			map.put("message", "PDF文件导出失败！");
		} else {
			map.put("success", true);
			map.put("message", "PDF文件导出成功！");
		}
		return map;
	}

	@ResponseBody
	@RequestMapping(value = { "/expoertdeduction" })
	public Map<String, Object> exportDeductionPdfByID(
			@RequestParam("standardId") String standardId, HttpSession session)
			throws DocumentException, IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean result = false;
		try {
			Long id = Long.valueOf(standardId);
			result = pdfService.exportDeductionPdfByID(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (!result) {
			map.put("success", false);
			map.put("message", "考核成绩导出失败！");
		} else {
			map.put("success", true);
			map.put("message", "考核成绩导出成功！");
		}
		return map;
	}
}
